package com.bluebench.bigul.domain.graphics.simple.polygon;

import java.util.List;

import com.bluebench.bigul.domain.graphics.Graphic;
import com.bluebench.bigul.domain.graphics.Line;
import com.bluebench.bigul.domain.graphics.Point;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.pdf.PdfContentByte;

public class Equilateral extends Triangle implements EquiPolygon{
	
	public Equilateral(PdfContentByte pdfContent) {
		super(pdfContent);	
	}	

	@Override
	Polygon build(Point start, List<Float> sides) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Polygon build(Point start, float side) {
		
		float x = start.getX();
		float y = start.getY();
		
		canvas.moveTo(x,y);        
        canvas.lineTo(x + side,y);
        canvas.lineTo(x + (side/2), (float)(y+(side*Math.sin(convertToRadian(60)))));
               
        vertices.add(new Point(x,y));
        vertices.add(new Point(x+side,y));
        vertices.add(new Point(x + (side/2),(float)(y+(side*Math.sin(convertToRadian(60))))));
        
        sides.add(new Line(side));
        sides.add(new Line(side));
        sides.add(new Line(side));
        
        return this;	
		
	}

	@Override
	protected boolean validate() {
		
		Point p1 = getVertices().get(0);		
		Point p2 = getVertices().get(1);		
		Point p3 = getVertices().get(2);
		
		float base = new Line(p1,p2).getLength();
		float side1 = new Line(p2,p3).getLength();
		float side2 = new Line(p3,p1).getLength();
		
		if(base==side1 && side1==side2){
			return true;
		}
		
		return false;
	}

	@Override
	public Graphic concentric(float distance, boolean in) {
		float x = vertices.get(0).getX();
		float y = vertices.get(0).getY();
		Point start=null;
		float side=0;
		if(in){
			start = new Point(x+distance,y+distance);
			//TODO : validate that lenght > 2d
			side = sides.get(0).getLength() - (2*distance);
		}else{
			start = new Point(x-distance,y-distance);
			//TODO : validate that lenght > 2d
			side = sides.get(0).getLength() + (2*distance);
		}
		return build(start,side);		
	}

	@Override
	public Polygon build(Point start, float side, float rotation) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Graphic copy(float distance, int direction) {
		// TODO Auto-generated method stub
		return null;
	}
	
	

}
